﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
 
using S22.Imap;

namespace Ession
{
    public class GmailTool
    { 

        public static MailMessage[] GetNewEmails(string userName, string pwd, bool madeSeen = false)
        {
            try
            {

                using (ImapClient Client = new ImapClient("imap.gmail.com", 993, userName, pwd, AuthMethod.Login, true))
                {
                    uint[] uids = Client.Search(SearchCondition.Unseen());

                    MailMessage[] ms = Client.GetMessages(uids);

                    if (madeSeen)
                    {
                        foreach (var u in uids)
                        {
                            Client.SetMessageFlags(u, null, MessageFlag.Seen);
                        }
                    }
                    return ms;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

            }
            finally
            {
            }
            return null;


        }
    }
}
